<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
      function SuperType(name) {
        this.name = name;
        this.colors = ["red", "blue", "green"];
      }
      //父类定义方法
      SuperType.prototype.sayName = function() {
        alert(this.name);
      }

      function SubType(name, age) {
        // 继承属性
        // SuperType.call(this, name);
        this.age = age;
      }

      // 继承父类方法
      SubType.prototype = new SuperType();
      //这里由于父类实例重写了原型,我们要给他手动加一个constructor
      SubType.prototype.constructor = SubType;
      //子类定义方法
      SubType.prototype.sayAge = function() {
        alert(this.age);
      };

      var instance1 = new SubType("Nicholas", 29);
      console.log(instance1)
    </script>
</body>
</html>